﻿using System;
using System.Web.Mail;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using MLY;
using MLY.Dal;
using MLY.Bll;
using System.IO;


namespace MLY.Reports.DataReports
{
    public partial class ExceptionsReportNoWithoutActual : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // checking logged in user
            if (clsUser.CurrentUserRoleId < 0)
            {
                Response.RedirectTo("/LTR/Login.aspx?ReturnTo=" + Request.Url.ToString());
            }

            // direction
            if (SessParam.Culture == "he")
            {
                //cssLiteral.Text = @"<link type=""text/css"" rel=""stylesheet"" href=""/Style/Rtl_Stylesheet.css"" />";
                DirectionPanel.Direction = ContentDirection.RightToLeft;
            }
            else
            {
                //cssLiteral.Text = @"<link type=""text/css"" rel=""stylesheet"" href=""/Style/Ltr_Stylesheet.css"" />";
                DirectionPanel.Direction = ContentDirection.LeftToRight;
            }
        }

        protected void Submit(object sender, EventArgs e)
        {
            DateTime PopulationFrom = DateTime.Parse(txtFromDate.Text.Trim());
            DateTime PopulationTill = DateTime.Parse(txtToDate.Text.Trim());

            ExportToExcelButton.Visible = true;

            DataSource.SelectParameters.Clear();
            DataSource.SelectParameters.Add("DateType", ddlLateOrderColumnDate.SelectedValue);
            DataSource.SelectParameters.Add("StartDate", Utils.SqlDate(PopulationFrom));
            DataSource.SelectParameters.Add("EndDate", Utils.SqlDate(PopulationTill));

            DataSource.DataBind();
            DataGrid.DataSourceID = "DataSource";
        }

        protected void ExportToExcel(object sender, EventArgs e)
        {
            MLY.Bll.ExcelExport.PrepareCsvFileFromGridview(DataGrid, "Open_lines_without_material");
        }

        protected string FormatDate(object Date)
        {
            string RetValue;

            try
            {
                RetValue = string.Format("{0:d}", DateTime.Parse(Date.ToString()));
            }
            catch
            {
                RetValue = ("");
            }
            return RetValue;


        }
    }
}
